package com.gzit.dialog;

import com.gzit.dialog.framework.ManagedActivityDialog;
import com.gzit.dialog.framework.ManagedDialogsActivity;

import android.app.AlertDialog;
import android.app.Dialog;
import android.content.Context;
import android.content.DialogInterface;
import android.util.Log;
import android.view.LayoutInflater;
import android.view.View;
import android.widget.EditText;

public class GenericPromptDialog extends ManagedActivityDialog {
	private String mPromptMessage = null;
	private View promptView = null;
	private int promptLayoutId;
	private int valueEditTextViewId;
	String promptValue = null;

	private Context ctx = null;

	public GenericPromptDialog(ManagedDialogsActivity inActivity, int dialogId,
			String promptMessage, int promptLayoutId, int valueEditTextViewId) {
		super(inActivity, dialogId);
		mPromptMessage = promptMessage;
		ctx = inActivity;
		this.promptLayoutId = promptLayoutId;
		this.valueEditTextViewId = valueEditTextViewId;
	}

	public Dialog create() {
		LayoutInflater li = LayoutInflater.from(ctx);
		promptView = li.inflate(promptLayoutId, null);
		AlertDialog.Builder builder = new AlertDialog.Builder(ctx);
		builder.setTitle("prompt");
		builder.setView(promptView);
		builder.setPositiveButton("OK", this);
		builder.setNegativeButton("Cancel", this);
		AlertDialog ad = builder.create();
		return ad;
	}

	public void prepare(Dialog dialog) {
		// nothing for now
	}

	public void onClickHook(int buttonId) {
		if (buttonId == DialogInterface.BUTTON1) {
			// ok button
			String promptValue = getEnteredText();
		}
	}

	private String getEnteredText() {
		EditText et = (EditText) promptView.findViewById(valueEditTextViewId);
		String enteredText = et.getText().toString();
		Log.d("xx", enteredText);
		return enteredText;
	}
}